// pages/inviteExtract/inviteExtract.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    codeIMG: "../../images/tb148.png",
    shuomignList: [],
    amount: '',
    thumbUrl: getApp().globalData.thumbUrl,
    chooseImg:""

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var uid = wx.getStorageSync('uid')
    var param = {
      uid: uid
    };
    app.wxRequest('POST', "Index/withdrawIntro", param, (res) => {
      var data = res.data;
      console.log(data)
      that.setData({
        userInfo: data.userInfo,
        shuomignList: data.describeArr,
      })
    }, (err) => {
      console.log(err.errMsg)
    })

  },
  allTsp: function () {
    var that = this;
    var userInfo = that.data.userInfo;
    that.setData({
      amount: userInfo.invitation
    })
  },
  formSubmit:function(e){
    var that=this;
    var amount = e.detail.value.amount;
    var chooseImg=that.data.chooseImg;
    if(parseFloat(amount) <= 0){
      wx.showToast({
        title: '请填写提现金额',
        icon:"none",
        duration:1500
      })
      return false;
    }
    if(!chooseImg || chooseImg == ""){
      wx.showToast({
        title: '请上传收款码',
        icon:"none",
        duration:1500
      })
      return false;
    }
    var uid = wx.getStorageSync('uid')
    var param = {
      uid: uid,
      amount:amount,
      qrcode:chooseImg
    };
    app.wxRequest('POST', "Index/invitationWith", param, (res) => {
      var code = res.code;
      if(code == 1){
        wx.showToast({
          title: res.msg,
          icon:"none",
          duration:1500
        })
        setTimeout(function(){
          wx.navigateBack({

          })
        },1500)
      }else{
        wx.showToast({
          title: res.msg,
          icon:"none",
          duration:1500
        })
      }
    }, (err) => {
      console.log(err.errMsg)
    })
    // console.log(e)
  },
  chooseImg: function () {
    var that=this;
    var thumbUrl=that.data.thumbUrl;
    wx.chooseImage({
      count: 1, // 最多可以选择的图片张数，默认9
      sizeType: ['original', 'compressed'], // original 原图，compressed 压缩图，默认二者都有
      sourceType: ['album', 'camera'], // album 从相册选图，camera 使用相机，默认二者都有
      success: function (res) {
        that.setData({
          codeIMG: res.tempFilePaths[0]
        })
        wx.uploadFile({
          filePath: res.tempFilePaths[0],
          name: 'file',
          url: thumbUrl+'/Index/UploadImg',
          success:function(e){
            var data=JSON.parse(e.data);
            that.setData({
              chooseImg:data.data
            })
            // console.log(data)
          }
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})